<template>
  <div>
    <el-drawer title="" :visible.sync="drawer" :direction="direction" :before-close="handleClose" custom-class="drawer-info">
      <div class="info-item">
        <h5 class="from-title">基本信息</h5>
        <div class="form-item">
          <label class="form-item-label">优惠券名称:</label>
          <div class="form-item-content">{{ objInfo.couponName }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">领取中心显示:</label>
          <div class="form-item-content">{{ objInfo.getTypeName }}</div>
        </div>
        <div class="form-item">
          <label class="form-item-label">每人限领张数:</label>
          <div class="form-item-content">{{ objInfo.getMax }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">领取卡券链接:</label>
          <div class="form-item-content">{{ objInfo.getUrl }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">消费方式:</label>
          <div class="form-item-content">{{ objInfo.useTypeName }}</div>
        </div>
        <div class="form-item">
          <label class="form-item-label">退回方式:</label>
          <div class="form-item-content">{{ objInfo.returnTypeName }}</div>
        </div>
        <div class="form-item">
          <label class="form-item-label">消费满多少可用 0 不限制:</label>
          <div class="form-item-content">{{ objInfo.enough }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">时间限制类型:</label>
          <div class="form-item-content">{{ objInfo.timeLimitName }}</div>
        </div>
        <div class="form-item">
          <label class="form-item-label">获得后可使用 0 不限时间 >0 天:</label>
          <div class="form-item-content">{{ objInfo.timeDays }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">开始时间:</label>
          <div class="form-item-content">{{ objInfo.timeStart }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">结束时间:</label>
          <div class="form-item-content">{{ objInfo.timeEnd }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">返利方式:</label>
          <div class="form-item-content">{{ objInfo.backTypeName }}</div>
        </div>
        <div class="form-item">
          <label class="form-item-label">抵扣:</label>
          <div class="form-item-content">{{ objInfo.deduct }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">折扣:</label>
          <div class="form-item-content">{{ objInfo.discount }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">介绍:</label>
          <div class="form-item-content" v-html="objInfo.desc"></div>
        </div>
        <div class="form-item">
          <label class="form-item-label">总发放数量:</label>
          <div class="form-item-content">{{ objInfo.total }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">购买价格:</label>
          <div class="form-item-content">{{ objInfo.money }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">消耗积分:</label>
          <div class="form-item-content">{{ objInfo.credit }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">排序:</label>
          <div class="form-item-content">{{ objInfo.displayOrder }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">是否限制商品:</label>
          <div class="form-item-content">{{ objInfo.limitGoodTypeName }}</div>
        </div>
        <div class="form-item">
          <label class="form-item-label">是否限制商品分类:</label>
          <div class="form-item-content">{{ objInfo.limitGoodCateTypeName }}</div>
        </div>
        <div class="form-item">
          <label class="form-item-label">限制商品分类:</label>
          <div class="form-item-content">{{ objInfo.limitGoodCateIds }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">限制商品:</label>
          <div class="form-item-content">{{ objInfo.limitGoodIds }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">是否限制会员级别 :</label>
          <div class="form-item-content">{{ objInfo.isLimitLevelName }}</div>
        </div>
        <div class="form-item">
          <label class="form-item-label">会员级别:</label>
          <div class="form-item-content">{{ objInfo.limitLevelIdsName }}</div>
        </div>
        <div class="form-item">
          <label class="form-item-label">状态:</label>
          <div class="form-item-content">{{ objInfo.statusName }}</div>
        </div>
        <div class="form-item">
          <label class="form-item-label">创建人:</label>
          <div class="form-item-content">{{ objInfo.createUserName }}</div>
        </div>
        <div class="form-item">
          <label class="form-item-label">创建时间:</label>
          <div class="form-item-content">{{ objInfo.createTime }}
          </div>
        </div>
        <div class="form-item">
          <label class="form-item-label">是否删除:</label>
          <div class="form-item-content" v-if="objInfo.isDeleted == 1">启用</div>
          <div class="form-item-content" v-else>禁用</div>
        </div>
      </div>
    </el-drawer>
  </div>
</template>
<script>
import { salecouponInfo } from "@/api/orders/salecoupon.js";
import { enumList,urlList, } from "@/api/public.api.js";
export default {
  data() {
    return {
      drawer: true,
      direction: "rtl",
      objInfo: {},
      YesNoList:[],
      CouponUseType_ordersList:[],
      CouponReturnType_ordersList:[],
      CouponTimeLimitType_ordersList:[],
      CouponBackType_ordersList:[],
      CouponLimitType_ordersList:[],
      limitLevelIdsList:[],
    }
  },
  created() {
  },
  methods: {
    queryEnumList(){
      this.YesNoList = [];
      enumList("YesNo","").then((resp) => {
        if (resp.code == 0) {
          this.YesNoList = resp.data;
        }
      });
      this.CouponUseType_ordersList = [];
      enumList("CouponUseType","orders").then((resp) => {
        if (resp.code == 0) {
          this.CouponUseType_ordersList = resp.data;
        }
      });
      this.CouponReturnType_ordersList = [];
      enumList("CouponReturnType","orders").then((resp) => {
        if (resp.code == 0) {
          this.CouponReturnType_ordersList = resp.data;
        }
      });
      this.CouponTimeLimitType_ordersList = [];
      enumList("CouponTimeLimitType","orders").then((resp) => {
        if (resp.code == 0) {
          this.CouponTimeLimitType_ordersList = resp.data;
        }
      });
      this.CouponBackType_ordersList = [];
      enumList("CouponBackType","orders").then((resp) => {
        if (resp.code == 0) {
          this.CouponBackType_ordersList = resp.data;
        }
      });
      this.CouponLimitType_ordersList = [];
      enumList("CouponLimitType","orders").then((resp) => {
        if (resp.code == 0) {
          this.CouponLimitType_ordersList = resp.data;
        }
      });
    },
    queryUrlList(){
      this.limitLevelIdsList = [];
      urlList("/member/memberLevel/list").then((resp) => {
        if (resp.code == 0) {
          if (resp.data) {
            resp.data.forEach((item) => {
              this.limitLevelIdsList.push({ code: item.id, name: item.name });
            });
          }
        }
      });
    },
    init(id) {
      this.queryEnumList();
      this.queryUrlList();
      if (id) {
        salecouponInfo(id).then(res => {
          this.objInfo = res.data
          let getTypeObj = this.YesNoList.find((item) => {
            return item.code == this.objInfo.getType;
          });
          this.objInfo.getTypeName = getTypeObj ? getTypeObj.name : "";
          let useTypeObj = this.CouponUseType_ordersList.find((item) => {
            return item.code == this.objInfo.useType;
          });
          this.objInfo.useTypeName = useTypeObj ? useTypeObj.name : "";
          let returnTypeObj = this.CouponReturnType_ordersList.find((item) => {
            return item.code == this.objInfo.returnType;
          });
          this.objInfo.returnTypeName = returnTypeObj ? returnTypeObj.name : "";
          let timeLimitObj = this.CouponTimeLimitType_ordersList.find((item) => {
            return item.code == this.objInfo.timeLimit;
          });
          this.objInfo.timeLimitName = timeLimitObj ? timeLimitObj.name : "";
          let backTypeObj = this.CouponBackType_ordersList.find((item) => {
            return item.code == this.objInfo.backType;
          });
          this.objInfo.backTypeName = backTypeObj ? backTypeObj.name : "";
          let limitGoodTypeObj = this.CouponLimitType_ordersList.find((item) => {
            return item.code == this.objInfo.limitGoodType;
          });
          this.objInfo.limitGoodTypeName = limitGoodTypeObj ? limitGoodTypeObj.name : "";
          let limitGoodCateTypeObj = this.CouponLimitType_ordersList.find((item) => {
            return item.code == this.objInfo.limitGoodCateType;
          });
          this.objInfo.limitGoodCateTypeName = limitGoodCateTypeObj ? limitGoodCateTypeObj.name : "";
          let isLimitLevelObj = this.YesNoList.find((item) => {
            return item.code == this.objInfo.isLimitLevel;
          });
          this.objInfo.isLimitLevelName = isLimitLevelObj ? isLimitLevelObj.name : "";
          let limitLevelIdsObj = this.limitLevelIdsList.find((item) => {
            return item.code == this.objInfo.limitLevelIds;
          });
          this.objInfo.limitLevelIdsName = limitLevelIdsObj ? limitLevelIdsObj.name : "";
          let statusObj = this.YesNoList.find((item) => {
            return item.code == this.objInfo.status;
          });
          this.objInfo.statusName = statusObj ? statusObj.name : "";
        })

      }
      this.drawer = true
    },
    // 关闭抽屉
    handleClose(done) {
      done()
    },
  },
}
</script>
<style scoped>
.from-title {
  margin-bottom: 20px;
  padding: 0 20px 20px 20px;
  font-size: 16px;
  color: #17233d;
  border-bottom: 1px solid #eee;
}
.info-item {
  margin-bottom: 40px;
}

.form-item {
  margin-bottom: 20px;
  font-size: 14px;
}
.form-item-label {
  text-align: right;
  float: left;
  width: 25%;
}
.form-item-content {
  margin-left: 30%;
  width: 70%;
}
</style>
